package net.oschina.archx.spring.aop;

import net.oschina.archx.annotation.AspectTest;
import org.aspectj.lang.ProceedingJoinPoint;
import org.aspectj.lang.annotation.Around;
import org.aspectj.lang.annotation.Aspect;
import org.aspectj.lang.annotation.Before;
import org.aspectj.lang.annotation.Pointcut;
import org.slf4j.Logger;
import org.slf4j.LoggerFactory;

/**
 * Created by Archx on 2015/6/16 0016.
 */
@Aspect
public class TestAspect {
    // see http://jinnianshilongnian.iteye.com/blog/1420689
    final Logger log = LoggerFactory.getLogger(this.getClass());

    @Pointcut(value = "execution(* net.oschina.archx..service..*+.*(..)) && args(name)", argNames = "name")
    public void beforePointcut(String name) {
    }

    @Before(value = "beforePointcut(name)", argNames = "name")
    public void beforeAdvice(String name) {
        log.info("注解方式 前置通知 ... 传入参数 name={}", name);
    }

    @Pointcut("@within(org.springframework.stereotype.Service) && @annotation(net.oschina.archx.annotation.AspectTest)")
    public void annotaionPointcut() {
    }

    @Around("annotaionPointcut() && @annotation(at)")
    public Object annotaionAdvice(ProceedingJoinPoint pjp, AspectTest at) throws Throwable {
        log.info("自定义注解访问 {}", at.value());
        return pjp.proceed();
    }
}
